<template>
  <a-modal
    title="角色信息"
    v-model="show"
    :maskClosable="false"
    :width="1050"
    placement="right"
    :closable="true"
    @cancel="onClose"
    :footer="null"
    :visiable="roleInfoVisiable"
  >
    <p><a-icon type="crown" />&nbsp;&nbsp;角色级别：{{ roleLevel }}</p>
    <p>
      <a-icon type="crown" />&nbsp;&nbsp;角色名称：{{ roleInfoData.roleName }}
    </p>
    <p :title="roleInfoData.remark">
      <a-icon type="book" />&nbsp;&nbsp;角色描述：{{ roleInfoData.roleDesc }}
    </p>
    <p>
      <a-icon type="clock-circle" />&nbsp;&nbsp;创建时间：{{
        roleInfoData.createTime
      }}
    </p>
    <p>
      <a-icon type="clock-circle" />&nbsp;&nbsp;修改时间：{{
        roleInfoData.lastUpdateTime ? roleInfoData.lastUpdateTime : "暂未修改"
      }}
    </p>
    <p>
      <a-icon type="trophy" />&nbsp;&nbsp;所拥有的权限：
      <a-tree
        :key="key"
        :checkable="true"
        :checkStrictly="false"
        :defaultCheckedKeys="checkedKeys[0]"
        :expandedKeys="checkedKeys[0]"
        :treeData="menuTreeData"
        :selectable="false"
        :disabled="true"
      >
      </a-tree>
    </p>
  </a-modal>
</template>
<script>
export default {
  name: "RoleInfo",
  props: {
    roleInfoVisiable: {
      require: true,
      default: false,
    },
    roleInfoData: {
      require: true,
    },
    roleInstId: "",
    roleCodeData: {
      type: Array,
      default: () => [],
    },
  },

  data() {
    return {
      key: +new Date(),
      loading: true,
      checkedKeys: [],
      menuTreeData: [],
      roleLevel: "",
    };
  },
  computed: {
    show: {
      get: function () {
        return this.roleInfoVisiable;
      },
      set: function () {},
    },
  },
  methods: {
    onClose() {
      this.$emit("close");
      this.checkedKeys = [];
    },
  },
  watch: {
    roleInfoVisiable() {
      if (this.roleInfoVisiable) {
        this.$get("admin/upmpmenu", {
          channelType: "00",
        }).then((r) => {
          this.menuTreeData = r.data.rows.children;
          console.log(this.menuTreeData, 11111);
          this.$get("admin/upmprole/menu/" + this.roleInfoData.id).then(
            (rst) => {
              console.log(this.checkedKeys);
              let length = this.checkedKeys.length;
              this.checkedKeys.splice(0, length, rst.data);
              console.log(this.checkedKeys);
              this.key = +new Date();
            }
          );
        });
        for (let i in this.roleCodeData) {
          let title = this.roleCodeData[i];
          if (title.label == this.roleInfoData.roleCode) {
            this.roleLevel = this.roleInfoData.roleCode + "-" + title.value;
          }
        }
      }
    },
  },
};
</script>
